package com.zjitc.service.impl;

import com.zjitc.mapper.UserMapper;
import com.zjitc.pojo.User;
import com.zjitc.service.UserSerivce;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserSerivce {
    @Autowired
    private UserMapper userMapper;

    @Override
    public String register(User user) {
        if (queryUserByUsername(user.getUsername())!=null) {
            return "用户已存在";
        }else {
            userMapper.register(user);
            return "";
        }

    }

    @Override
    public User queryUserByUsername(String username) {
        return userMapper.queryUserByUsername(username);
    }

    @Override
    public String login(User user){
        User one_user = queryUserByUsername(user.getUsername());
        if (one_user==null){
            return "用户不存在，请先注册";
        }else if (one_user.getPassword().equals(user.getPassword())){
            return "";
        }else {
            return "密码错误";
        }
    }
}
